<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : collection.class.php   FILE_PATH : \\classes\application\collection.class.php
 * ....收藏操作类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Sat Sep 15 16:07:51 CST 2007
 */

class CollectionClass extends FrameWork {
	/**
	 * 新增收藏
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	
	function addCollection($input_param){
		if (intval($input_param['memberid']) > 0){
			$valueArray = array();
			$valueArray['member_id'] = $input_param['memberid'];
			$valueArray['collection'] = $input_param['collection'];
			$valueArray['genre'] = $input_param['genre'];
			$valueArray['intro'] = $input_param['txtIntro'];
			$valueArray['collection_time'] = time();
			$is_exist = $this->isExistCollection(intval($valueArray['member_id']),$valueArray['collection'],$valueArray['genre']);
			if ($is_exist == false){
				$insert_rs = $GLOBALS['db']->InsertRow($valueArray, 'collection', 'collection_id');
				return $insert_rs;
			}else{
				return false;
			}
		}else {
			return false;
		}
	}

	/**
	 * 是否存在此收藏
	 *
	 * @param int $member_id
	 * @param int $collection
	 * @param string $genre
	 * @return boolen
	 */
	function isExistCollection($member_id,$collection,$genre){
		$exist_row = $GLOBALS['db']->GetList("and member_id='" . $member_id . "' and collection='" . $collection . "' and genre='" . $genre . "'",$page,'collection');
		return $exist_row;
	}

	/**
	 * 修改收藏内容
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function modiCollection($input_param){
		$valueArray = array();
		$valueArray['intro'] = $input_param['txtIntro'];
		$update_rs = $GLOBALS['db']->UpdateRow($input_param['collectionid'],$valueArray, 'collection', 'collection_id');
		return $update_rs;
	}

	/**
	 * 得到收藏内容列表
	 *
	 * @param obj $obj_page   分页对象
	 * @param int $member_id   用户ID
	 * @param string $genre   收藏种类
	 * @return var[]
	 */
	function getCollection(&$obj_page,$member_id,$genre){
		if ($genre == "store"){
			$list_rs = $GLOBALS['db']->GetJoinList($obj_page,array('collection','shop_info'),"left join",array("collection=shop_info.member_id"),array('collection_id,collection,intro,genre,collection_time','*'),"where collection.member_id='" . $member_id . "' and collection.genre='" . $genre . "'",0,array("collection_time desc"));
		}else if ($genre == "product"){
			$list_rs = $GLOBALS['db']->GetJoinList($obj_page,array('collection','product','member'),"left join",array("collection=product.p_id","member.member_id = product.member_id"),array('collection_id,collection,intro,genre,collection_time','*','login_name,email,member_state,member_type,regist_time,last_login_time'),"where collection.member_id='" . $member_id . "' and collection.genre='" . $genre . "'",0,array("collection_time desc"));
		}
		return $list_rs;
	}
	
	/**
	 * 删除某个收藏
	 *
	 * @param var[] $input_id
	 * @param int $member_id
	 * @return boolen
	 */
	function deleteOperateCollection($input_id,$member_id){
		if (is_array($input_id)){
			foreach ($input_id as $value){
				$this->_deleteCollection($value,$member_id);
			}
		}else{
			$this->_deleteCollection($input_id,$member_id);
		}
		return true;
	}
	/**
	 * 删除收藏
	 */
	function deleteCollection($collection,$member_id,$genre){
		if (intval($member_id) > 0){
			$del_rs = $GLOBALS['db']->DeleOneRow('','collection','',"collection = '" . $collection . "' and member_id='" . $member_id . "' and genre='" . $genre . "'");
			return $del_rs;
		}else {
			return false;
		}
	}
	
	
	/**
	 * 删除某个商铺的友情连接
	 *
	 * @param int $link_id
	 * @param int $shop_id
	 * @return boolen
	 */
	function _deleteCollection($input_id,$member_id){
		if (intval($input_id) > 0 && intval($member_id) > 0){
			$del_rs = $GLOBALS['db']->DeleOneRow('','collection',''," and collection_id = " . intval($input_id) . " and member_id='" . intval($member_id) . "'");
			return $del_rs;
		}
		return false;	
	}
}
?>